import torch

tensor2d = torch.tensor([[1, 2, 3], [4, 5, 6]])
print("tensor2d: ", tensor2d)

print("tensor2d.shape: ", tensor2d.shape)

print("tensor2d.reshape(3, 2): ", tensor2d.reshape(3, 2))

# the more common command for reshaping tensors in pytorch is view
print("tensor2d.view(3, 2)", tensor2d.view(3, 2))

# .T to transpose a tensor
print("tensor2d.T", tensor2d.T)

# the common way to multiply two matrics in pytorch is the .matmul method
"""
      A                B
--------------------------------
  1   2   3          1   4
  4   5   6   ×      2   5
                     3   6

tensor multiple condition： A's column equal to B's row                
A: shape is (m, n), B: shape is (n, k), 则 A * B shape is (m, k), so matmul result shap is (2, 2)
function: C[i][j] = sum(A[i][p] * B[p][j] for p in 0..k-1)

C[0,0] = 1 * 1 + 2 * 2 + 3 * 3 = 14 
C[0, 1] = 1 * 4 + 2 * 5 + 3 * 6 = 32
C[1, 0] = 4 * 1 + 5 * 2 + 6 * 3 = 32
C[1, 1] = 4 * 4 + 5 * 5 + 6 * 6 = 77
"""
print("tensor2d.matmul", tensor2d.matmul(tensor2d.T))

# @ equal matmul
print("tensor2d @", tensor2d @ tensor2d.T)